<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2020/8/10
 * Time: 16:56
 */

namespace App\HttpController\SupportPerson;

use App\Services\ReponseCodeService;
use App\Services\SupportPersonService;
use EasySwoole\Validate\Validate;

class SupportPerson extends SupportPersonBaseController
{
    /**
     * showdoc
     * @catalog   客服后台/客服
     * @title  客服登录
     * @description 客服登录
     * @method POST
     * @url /supportPerson/login
     * @param username  是 string 用户名
     * @param password 是 string 密码
     * @return_param  code int 状态码(200:成功0:失败400:参数错误)
     * @return_param  username 用户名
     * @return_param  realname 真实姓名
     * @return_param  head 头像
     * @return_param  mobile 手机号
     * @return_param  created_at 创建时间
     * @return_param  updated_at更新时间
     * @remark
     */
    public function login(){
        $param =  $this->param;
        $valitor = new Validate();
        $valitor->addColumn('username', '用户名')->required('用户名不为空');
        $valitor->addColumn('password','密码')->required('密码不能为空');

        $bool = $valitor->validate($param);
        if(!$bool){
            return $this->writeJson(ReponseCodeService::CODE_BAD_REQUEST, null, $valitor->getError()->__toString());
        }

        $supportPersonService = new SupportPersonService();
        $loginInfo =  $supportPersonService->login( $param);
        if(!is_array($loginInfo)){
            return $this->writeJson(ReponseCodeService::CODE_FAILE, null, ReponseCodeService::$phrases[ReponseCodeService::CODE_FAILE]);
        }
        return   $this->writeJson(ReponseCodeService::CODE_OK,$loginInfo, ReponseCodeService::$phrases[ReponseCodeService::CODE_OK]);
    }
}